package com.example.mobile2121606110syc0330homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private ImageView imageView;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        button.setOnClickListener(new View.OnClickListener() {
            private boolean flag;
            @Override
            public void onClick(View view) {
                if (flag){
                    imageView.setImageResource(R.drawable.off);
                }
                else{
                    imageView.setImageResource(R.drawable.on);
                }
                flag = !flag;
            }
        });

    }

    private void initView() {
        imageView = (ImageView) findViewById(R.id.imageView);
        button = (Button) findViewById(R.id.button);
    }
}